/**
 * LinkInfo.java
 *
 * @author Hagen Boehm
 */


package SSF.OS.OSPFv2;


import SSF.Net.Util.IP_s;


// ======================= class SSF.OS.OSPFv2.LinkInfo ====================== //
/**
 * A unit of information describing a link and used in the contents of a link
 * state advertisement.
 */
public class LinkInfo {

  // ......................... constants ........................... //
  /** The size of this Link Info. Orientated by RFC 2328. */
  public static final int LINK_INFO_SIZE = 12;

  // ........................ member data .......................... //
  
  /** This variable holds the ID of the link. */
  public int linkID;
  
  /** This holds additional data about the link. */
  public int linkData;

  /** This field holds the type of the link. */
  public int linkType;

  /** The number of different TOS metrics given for this link. */
  public int numOfTOSMetrics;
  
  /** The cost of using this router link. */
  public int metric;

  // ------------------------ constructor LinkInfo -------------------------- //  
  /**
   * Constructs a new unit of link information given router and link
   * information.
   */
  public LinkInfo(int id, int data, int type, int tos, int met) {
    linkID          = id;
    linkData        = data;
    linkType        = type;
    numOfTOSMetrics = tos;
    metric          = met;
  }

  public LinkInfo(int id, int data, int type, int met) {
    this(id, data, type, 0, met);
  }
  
  // ---------------------- LinkInfo.toString(boolean) --------------------- //
  /**
   * Converts the link information to a string.
   *
   * @return the link information as a string
   */
  public String toString() {
    String str = "";
    str += "   LinkID= " + IP_s.IPtoString(linkID) + " | LinkData= " + IP_s.IPtoString(linkData)
           + " | Type= " + linkType + " | #TOS metrics= " + numOfTOSMetrics + " | Metric= "
	   + metric;

    return str;
  }

  // ---------------------------- LinkInfo.size ---------------------------- //
  /** returns the size of this LinkInfo. */
  public static int size() {
    return LINK_INFO_SIZE;
  }

  // --------------------------- LinkInfo.equals --------------------------- //
  /**
   * Determines if a given object describes the same link as this object.
   *
   * @return true only if the object is of type LinkInfo and describes the same
   * link as this object
   */
  public boolean equals(Object o) {
    return (o instanceof LinkInfo &&
            ((LinkInfo)o).linkID == linkID &&
            ((LinkInfo)o).linkData == linkData &&
            ((LinkInfo)o).linkType == linkType);
  }

  // ---------------------------- LinkInfo.copy ------------------------------ //
  /** Return an exact copy of this LinkInfo */
  public LinkInfo copy() {
    LinkInfo linkInfo = new LinkInfo(linkID, linkData, linkType, numOfTOSMetrics, metric);
    return linkInfo;
  }

  // --------------------------- LinkInfo.compare ------------------------------- //
  /** Take a LinkInfo an compare it to this LinkInfo. If there is no difference
   *  between them return true else false.
   */
  public boolean compare(LinkInfo test) {
    if (test.linkID != linkID) return false;
    if (test.linkData != linkData) return false;
    if (test.linkType != linkType) return false;
    if (test.numOfTOSMetrics != numOfTOSMetrics) return false;
    if (test.metric != metric) return false;
    return true;
  }

} // end class LinkInfo









